<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<html>
    <head>
        <base target="_self" />
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">
        <title>修改角色菜单信息</title>
        <link rel="stylesheet" type="text/css" href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
        <link rel="stylesheet" type="text/css"
            href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
        <script type="text/javascript"
            src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
        <script type="text/javascript"
            src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
        <script type="text/javascript"
            src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
        <script type="text/javascript"
            src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
        <script type="text/javascript"
            src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
        <script type="text/javascript"
            src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
        <script type="text/javascript" src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>       

 
    <script type="text/javascript">
        function initList(listDisplayEId) {
                $('#' + listDisplayEId).datagrid(
                        {
                            nowrap : false,
                            striped : true,
                            collapsible : true,
                            remoteSort : true,
                            notSelectByRow : false,
                            frozenColumns : [ [ {
                                field : 'ids',
                                checkbox : true
                            } ] ],
                            toolbar : [ ],
                            onLoadError:function(){
                                $.messager.alert('错误','获取数据失败，请与管理员联系！','error');
                            }
                        });
            };
            $(document).ready(function() {
                initList('listDisplay');
                $('#isActive').combobox('select', '${role.isActive }');
                loadRoleMenus();
            });
            
        //修改信息按钮响应函数
        function updateRole(){
            $('#AddRoleForm').form('submit',
            {
                url:'<c:url value='/role/updateRole.do'/>', //查询提交路径
                onSubmit:function()//提交按钮相应函数
                {
                    if($('#roleName').val().trim()==""){
                        $.messager.alert("提示", "角色名不能为空！", 'info');
                        return false;
                    }
                    if($(".menuIds:checked").length==0){
                        $.messager.alert("提示", "请至少选择一个菜单！", 'info');
                        return false;
                    }
                },
                success:function(data){
                    data = JSON.parse(data);
                    if(data.success){
                        $.messager.alert("提示", "保存成功！", 'info');
                        window.close();
                    }else{
                        $.messager.alert("提示", "保存失败！", 'warning');
                        window.close();
                    }
                },
                error:function(){
                    $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
                    return;
                }
            });
            
        }
        function loadRoleMenus(){
            var roleId = $('#roleId').val();
            $.ajax({
                url : "<c:url value='/role/findRoleMenus.do'/>",
                async : true,
                data : {
                    roleId : roleId
                },
                dataType : 'json',
                success : function(data) {
                    //status =  data.codeName;
                    //alert(data);
                    var menuList = data.menus;
                    for(var i=0;i<menuList.length;i++){
                        $('.menuIds').each(function(){
                            if($(this).val()==menuList[i].menuId){
                                $(this).attr("checked",true);
                                return false;
                            }
                        });
                    }
                }

            });
        }
    </script>
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
  </head>

  <body>
    <table width="90%" align="center">
      <tr></tr>
      <tr>
        <td>
        
          <div style="height: auto; background: #fafafa; padding: 5px;" class="easyui-panel" title="修改角色菜单信息" iconCls="icon-save" 
          collapsible="true" minimizable="false" maximizable="false" closable="false">
            
            <form id="AddRoleForm" name="AddRoleForm" method="post">
               <table cellpadding="5">
                  <tr>
                    <td><input type="hidden" value="${role.roleId }" id="roleId" name="roleId"></td>
                  </tr>
                  <tr>
                  <td>角色名:</td>
                  <td>
                  <input class="easyui-validatebox" type="text" value="${role.roleName }" id="roleName" name="roleName" required="true" validType="length[1,30]"/>
                  </td>
                  </tr>
                  
                   <tr> 
                    <td>是否有效:</td>
                  <td>
                   <select class="easyui-combobox" id="isActive" name="isActive">
                   <option value="Y">有效</option> 
                   <option value="N">失效</option>
                   </select>
                  </td>
                  </tr>
                  
               </table>
               <br><br>
                -----------------------菜单选择----------------------------<br><br>
                <c:forEach var="menu" items="${menuList}" varStatus="status">
                         <input  type="checkBox" class="menuIds"  name="menuIds"
                           value="${menu.menuId }">${menu.menuName }</input>
                            <c:if test="${status.count % 5 == 0}">
                              <br><br>
                           </c:if>
                            
                 </c:forEach>
                  <br><br>
                 <a class="easyui-linkbutton" onclick="updateRole()">修改</a>
            </form>
          
          </div>
        </td>
      </tr>
    </table>
  </body>
</html>